package org.jivesoftware.spark.crowd.packet;

import org.jivesoftware.spark.crowd.Param;

public class PacketAssembler {
	private static PacketAssembler instance;
	private StringBuilder sb;
	private String serviceName = Param.CROWD_SERVICE_NAME;
	public static PacketAssembler getinstance(){
		if(instance == null)
			instance = new PacketAssembler();
		return instance;
	}
	private PacketAssembler(){
		
	}
	
	public String getCreatePacket(String crowdName,String title){
		sb = new StringBuilder();
		sb.append("<" )
			.append(serviceName)
		.append		(" xmlns=\"")
		
		.append(Param.create_NS)
		.append("\" name=\"")
		.append(crowdName)
		.append("\" title=\"")
		.append(title)
		.append("\"/>");
		
		return sb.toString();
	}
	
	
	
	public String getIAndAPacket( String crowdName,String xmlns){
		sb = new StringBuilder();
		
		
		sb.append("<" )
		.append(serviceName)
		.append	(" xmlns=\"")
		.append(xmlns)
		.append("\"")
		.append(" crowdname=\"")
		.append(crowdName)
		.append("\"")		
		.append("/>");
		
		return sb.toString();
	}
	public String getSendResult(String crowdName, String toJID,
			String result, String ns) {
		sb = new StringBuilder();
		sb.append("<" )
		.append(serviceName)
		.append	(" xmlns=\"")
		.append(ns)
		.append("\"")
		.append(" result=\"")	
		.append(result)
		.append("\"")
		.append(" crowdname=\"")
		.append(crowdName)
		.append("\"")
		.append(" tojid=\"")
		.append(toJID)
		.append("\"/>");
		return sb.toString();
	}
	public String getInvitePacket(String inviteeJID, String creatorJID,
			String crowdName) {
		sb = new StringBuilder();
		sb.append("<" )
		.append(serviceName)
		.append	(" xmlns=\"")
		  .append(Param.invite_NS )
		  .append("\"" )
		  .append(" crowdname=\"")
		  .append(crowdName)
		  .append("\"")
		  .append(" inviteejid=\"")
		  .append(inviteeJID)
		  .append("\"")
		  .append(" creatorjid=\"")
		  .append(creatorJID)
		  .append("\"")
		  .append("/>");
		return null;
	}
	public String getQuitPacket(String crowdName) {
		sb = new StringBuilder();
		sb.append("<" )
		.append(serviceName)
		.append	(" xmlns=\"")
		.append(Param.quit_NS)
		.append("\"")
		.append(" crowdname=\"")
		.append(crowdName)
		.append("\"/>");
		return sb.toString();
	}
	public String getDismissPacket(String crowdName) {
		sb = new StringBuilder();
		sb.append("<" )
		.append(serviceName)
		.append	(" xmlns=\"")
		  .append(Param.destroy_NS)
		  .append("\"")
		  .append(" name=\"")
		  .append(crowdName)
		  .append("\"/>");
		return sb.toString();
	}
	public String getSearchPacket(String contained) {
		sb = new StringBuilder();
		sb.append("<" )
		.append(serviceName)
		.append	(" xmlns=\"")
		  .append(Param.search_NS)
		  .append("\"")
		  .append(" reg=\"")
		  .append(contained)
		  .append("\"/>");
		
		return sb.toString();
	}
	public String getMessagePacket(String crowdName) {
		sb = new StringBuilder();
		sb.append("<")
		.append(Param.CROWD_SERVICE_NAME)
		.append(" xmlns=\"")
		.append(Param.message_NS)
		.append("\"")
		.append(" crowdname=\"")
		.append(crowdName)
		.append("\"/>");
		return sb.toString();
	}
}
